<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>

<title>Rapyd Library Guide</title>

<style type='text/css' media='all'>@import url('../userguide.css');</style>
<link rel='stylesheet' type='text/css' media='all' href='../userguide.css' />

<script type="text/javascript" src="../nav/nav.js"></script>
<script type="text/javascript" src="../nav/prototype.lite.js"></script>
<script type="text/javascript" src="../nav/moo.fx.js"></script>
<script type="text/javascript" src="../nav/syntax.js"></script>
<script type="text/javascript" src="../nav/syntax_php.js"></script>
<link type="text/css" href="../syntax.css" rel="stylesheet" /></head>
<body>

<!-- START NAVIGATION -->
<script type="text/javascript">create_header('../');</script>
<!-- END NAVIGATION -->


<!-- START BREADCRUMB -->
<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
<tr>
<td id="breadcrumb">
<a href="http://www.rapyd.com/">Rapyd Library Home</a> &nbsp;&#8250;&nbsp;
<a href="../index.html">Rapyd Guide</a> &nbsp;&#8250;&nbsp;
DataGrid Class
</td>
<td id="searchbox">
<script type="text/javascript">create_search();</script>
</td>
</tr>
</table>
<!-- END BREADCRUMB -->

<br clear="all" />


<!-- START CONTENT -->
<div id="content">


<h1>DataGrid Class</h1>

<img src="../images/datagrid.gif" />

<p>
DataGrid is a grid (html table) of records, where each row is a record, and each column is a field (like a dbms table layout).<br />
It has a <a href="../general/views.html">view</a>.<br />
It can use the rapyd <a href="../general/concepts.html#pattern">pattern</a> concept.
</p>

<h3>Sample</h3>
<textarea name="code" class="php:nogutter:nocontrols" rows="15" cols="100">

  $this->rapyd->load("datagrid");

  $grid = new DataGrid("Article List", "articles");
  $grid->per_page = 5;
  $grid->column_detail("Id","article_id", site_url('rapyd/crudsamples/dataedit/show/<#article_id#>')); 
  $grid->column("Title", "title");
  $grid->column("Body",  "body");
  $grid->build();


  $data["grid_output"] = $grid->output;
  $data["rapyd_head"] = $this->rapyd->get_head();
 </textarea>

<p>
cell_template pattern will be used to build table cells.<br/>
Can be a  custom html content, and use the rapyd <a href="../general/concepts.html#pattern">pattern</a> concept.
</p>

<p class="important"><strong>Important:</strong>&nbsp;
DataGrid extends DataSet, so inherit all properties and methods.</p>


<h2>DataGrid Reference</h2>

<p>
<dfn>$grid = new DataGrid($title, $datasource);</dfn>
</p>
<p> string: <kbd>$title</kbd> (can be null) is a simple label.</p>
<p> mixed: <kbd>$datasource</kbd> is a source of data. See rapyd <a href="../general/concepts.html#data">datasource</a> concept.</p>


<h5>Settings</h5>

<table cellpadding="0" cellspacing="1" border="0" style="width:100%" class="tableborder">
<tr>
  <th>Property</th>
  <th>Default&nbsp;Value</th>
  <th>Options</th>
  <th>Description</th>
</tr>
<tr>
  <td><strong>base_url</strong></td>
  <td>Current URL</td>
  <td>a URL </td>
  <td>* url of the controller function of dataset (autodetected). </td>
</tr>
<tr>
  <td><strong>uri_segment</strong></td>
  <td>Last segment</td>
  <td>numeric</td>
  <td>* offset segment in the uri (autodetected).</td>
</tr>
<tr>
  <td><strong>per_page</strong></td>
  <td>No Default</td>
  <td>numeric</td>
  <td>* number of record per page. <br /></td>
</tr>
<tr>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
</tr>
<tr>
  <td><strong>num_links</strong></td>
  <td>2</td>
  <td>numeric</td>
  <td>The number of "digit" links you would like before and after the selected page number. For example, the number 2 will place two digits on either side, as in the example links at the very top of this page.</td>
</tr>
<tr>
  <td>**</td>
  <td>**</td>
  <td>**</td>
  <td>**</td>
</tr>
</table>
<p>
(*) from CI pagination class.
</p>
<p>
(**) If you need to customize nav links you can pass  as parameter all <a href="../../user_guide/libraries/pagination.html" target="_blank">CI pagination configs</a>
</p>
<p class="important"><strong>Important:</strong>&nbsp;
Since 0.9.6 the <strong>base_uri</strong> an <strong>uri_segment</strong> need to specify/count  the "osp" (offset position) so:<br />
base_uri will be like: "controller/function/osp" and<br/>
uri_segment will be: 4 not 3.
</p>

<h5>Methods</h5>

<p>
<strong>$grid->use_function($functionname [, $other_function_name..])</strong>
</p>
<p>
Allow a function to be used by tag-engine (<a href="../general/concepts.html#pattern">pattern</a> concept) to format cell output<br/>
</p>
<br/>

<p>
<strong>$grid->column_detail($label, $pattern, $link, $extra_td_attributes)</strong>
</p>
<p>
append "link" column that can be used to link a <a href="dataedit.html">dataedit</a> based page.
</p>
<br/>

<p>
<strong>$grid->column($label, $pattern, $extra_td_attributes)</strong>
</p>
<p>
append a normal column.
</p>
<br/>

<p>
<strong>$grid->column_orderby($label, $pattern, $orderby_field, $extra_td_attributes)</strong>
</p>
<p>
append a orderby column.
</p>
<br/>

<p>
<strong>$grid->build();</strong>
</p>
<p>
Exec queries if datasource is ActiveRecord, and fill <strong>$grid->output</strong> html result</strong>
</p>


<h5>Output</h5>

<table cellpadding="0" cellspacing="1" border="0" style="width:100%" class="tableborder">
<tr>
  <th>Property</th>
  <th>Type</th>
  <th>Description</th>
</tr>
<tr>
  <td><strong>output</strong></td>
  <td>html</td>
  <td>html grid with the subset of results for current page, plus navigation links</td>
</tr>
</table>





</div>
<!-- END CONTENT -->


<script type="text/javascript">create_footer();</script>

</body>
</html>